package com.github.llyb120.szuniver.document.ctrl.shop;

import com.github.llyb120.szuniver.document.entity.Category;
import com.github.llyb120.szuniver.document.entity.CategoryTree;
import com.github.llyb120.szuniver.document.service.CategoryService;
import com.mongodb.client.MongoDatabase;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Administrator
 * @Date: 2020/9/23 17:07
 */
@RequestMapping("/api/admin/category")
@RestController
public class CategoryCtrl {

    @Resource
    CategoryService categoryService;

    public Object add(){
        return "fuck";
    }

    @PostMapping("save")
    public boolean save(
        @Validated @RequestBody Category category
        ){
        return categoryService.save(category);
    }

    @GetMapping("getChildrenByPid")
    public List<Category> getChildrenByPid(
        @RequestParam(required = false) String id
    ){
        return categoryService.getChildrenByPid(id);
    }

    @GetMapping("getAllCategories")
    public List<Category> getAllCategories(){
        return categoryService.getAllCategories();
    }
}
